package Demo;

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.File;

public class Embed extends JPanel {
    private SpringLayout springLayout;
    private static final long serialVersionUID = 1L;
    private String inputFilePath = "";
    private String outputFilePath = "";
    JarFileLoader jarLoader;

    public Embed() {
        this.setLayout(new GridBagLayout());
        this.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
        this.jarLoader = new JarFileLoader();
        this.setSize(500, 350);
        JPanel panel = new JPanel();
        this.springLayout = new SpringLayout();
        panel.setLayout(this.springLayout);
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.anchor = 17;
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.ipadx = 500;
        gridBagConstraints.ipady = 375;
        this.add(panel, gridBagConstraints);
        JLabel inputFileLabel = new JLabel();
        panel.add(inputFileLabel);
        this.springLayout.putConstraint("West", inputFileLabel, 22, "West", panel);
        this.springLayout.putConstraint("North", inputFileLabel, 40, "North", panel);
        inputFileLabel.setMinimumSize(new Dimension(5, 2));
        inputFileLabel.setMaximumSize(new Dimension(6, 2));
        //inputFileLabel.setText("input  file :");
        inputFileLabel.setText("输入文件 :");
        JButton browserButton = new JButton();
        panel.add(browserButton);
        browserButton.setText("浏览");
        JLabel outputFileLabel = new JLabel();
        panel.add(outputFileLabel);
        this.springLayout.putConstraint("East", outputFileLabel, 82, "West", panel);
        this.springLayout.putConstraint("West", outputFileLabel, 22, "West", panel);
        this.springLayout.putConstraint("North", outputFileLabel, 78, "North", panel);
        //outputFileLabel.setText("output file :");
        outputFileLabel.setText("输出文件 :");
        final JTextField outputFileArea = new JTextField();
        panel.add(outputFileArea);
        this.springLayout.putConstraint("North", outputFileArea, 73, "North", panel);
        outputFileArea.setName("outputFileArea");
        outputFileArea.setMargin(new Insets(3, 2, 2, 6));
        outputFileArea.setMinimumSize(new Dimension(12, 2));
        outputFileArea.setText("");
        JButton browserButton_1 = new JButton();
        panel.add(browserButton_1);
        this.springLayout.putConstraint("South", browserButton_1, 101, "North", panel);
        this.springLayout.putConstraint("North", browserButton_1, 5, "South", browserButton);
        this.springLayout.putConstraint("East", browserButton_1, 88, "East", outputFileArea);
        this.springLayout.putConstraint("West", browserButton_1, 5, "East", outputFileArea);
        browserButton_1.setText("浏览");
        JLabel watermarkLabel = new JLabel();
        panel.add(watermarkLabel);
        this.springLayout.putConstraint("East", watermarkLabel, 0, "East", inputFileLabel);
        this.springLayout.putConstraint("South", watermarkLabel, 130, "North", panel);
       // watermarkLabel.setText("Watermark :");
        this.springLayout.putConstraint("West", watermarkLabel, 22, "West", panel);
        watermarkLabel.setText("添加水印 :");
        final JTextField watermarkArea = new JTextField();
        watermarkArea.setAction((Action)null);
        panel.add(watermarkArea);
        this.springLayout.putConstraint("East", watermarkArea, 293, "East", watermarkLabel);
        this.springLayout.putConstraint("West", watermarkArea, 5, "East", watermarkLabel);
        this.springLayout.putConstraint("East", outputFileArea, 0, "East", watermarkArea);
        this.springLayout.putConstraint("West", outputFileArea, 5, "East", outputFileLabel);
        this.springLayout.putConstraint("South", watermarkArea, 134, "North", panel);
        this.springLayout.putConstraint("North", watermarkArea, 107, "North", panel);
        watermarkArea.setMargin(new Insets(3, 2, 2, 6));
        watermarkArea.setText("");
        JLabel keyLabel = new JLabel();
        panel.add(keyLabel);
        this.springLayout.putConstraint("North", keyLabel, 150, "North", panel);
        this.springLayout.putConstraint("East", keyLabel, 87, "West", panel);
        this.springLayout.putConstraint("West", keyLabel, 22, "West", panel);
        //keyLabel.setText("    key :");
        keyLabel.setText("输入密钥 :");
        JLabel imformationLabel = new JLabel();
        panel.add(imformationLabel);
        this.springLayout.putConstraint("East", imformationLabel, 77, "West", watermarkLabel);
        this.springLayout.putConstraint("West", imformationLabel, 5, "West", watermarkLabel);
        //imformationLabel.setText("Imformation:");
        imformationLabel.setText("嵌入信息：");
        JButton embedButton = new JButton();
        panel.add(embedButton);
        this.springLayout.putConstraint("South", imformationLabel, 23, "South", embedButton);
        this.springLayout.putConstraint("North", imformationLabel, 5, "South", embedButton);
        this.springLayout.putConstraint("North", embedButton, 190, "North", panel);
        this.springLayout.putConstraint("West", embedButton, 185, "West", panel);
        embedButton.setText("嵌入");
        final JTextField inforArea = new JTextField();
        panel.add(inforArea);
        this.springLayout.putConstraint("East", inforArea, 470, "West", panel);
        this.springLayout.putConstraint("West", inforArea, 0, "West", imformationLabel);
        this.springLayout.putConstraint("South", inforArea, 100, "South", imformationLabel);
        this.springLayout.putConstraint("North", inforArea, 0, "South", imformationLabel);
        final JTextField inputFileArea = new JTextField();
        inputFileArea.setMargin(new Insets(3, 2, 2, 6));
        panel.add(inputFileArea);
        this.springLayout.putConstraint("South", browserButton, 27, "North", inputFileArea);
        this.springLayout.putConstraint("North", browserButton, 0, "North", inputFileArea);
        this.springLayout.putConstraint("East", browserButton, 88, "East", inputFileArea);
        this.springLayout.putConstraint("West", browserButton, 5, "East", inputFileArea);
        this.springLayout.putConstraint("South", inputFileArea, -5, "North", outputFileArea);
        this.springLayout.putConstraint("North", inputFileArea, -32, "North", outputFileArea);
        this.springLayout.putConstraint("East", inputFileArea, 293, "East", inputFileLabel);
        this.springLayout.putConstraint("West", inputFileArea, 5, "East", inputFileLabel);
        final JTextField keyArea = new JTextField();
        keyArea.setText("");
        keyArea.setMargin(new Insets(3, 2, 2, 6));
        panel.add(keyArea);
        this.springLayout.putConstraint("South", keyArea, 172, "North", panel);
        this.springLayout.putConstraint("North", keyArea, 145, "North", panel);
        this.springLayout.putConstraint("East", keyArea, 288, "East", keyLabel);
        this.springLayout.putConstraint("West", keyArea, 0, "East", keyLabel);
        browserButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JFileChooser chooser = new JFileChooser();
                chooser.setCurrentDirectory(new File("."));
                int returnValue = chooser.showOpenDialog(chooser);
                if (returnValue == 0) {
                    File file = chooser.getSelectedFile();
                    Embed.this.inputFilePath = file.getAbsolutePath();
                    inputFileArea.setText(Embed.this.inputFilePath);
                }

            }
        });
        browserButton_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                JFileChooser chooser = new JFileChooser();
                chooser.setCurrentDirectory(new File("."));
                int returnValue = chooser.showSaveDialog(chooser);
                if (returnValue == 0) {
                    chooser.getSelectedFile().getName();
                    Embed.this.outputFilePath = chooser.getSelectedFile().getAbsolutePath();
                    outputFileArea.setText(Embed.this.outputFilePath);
                }

            }
        });
        embedButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                OP alg = new OP();
                boolean var3 = false;

                int key;
                try {
                    key = Integer.parseInt(keyArea.getText());
                } catch (Exception var6) {
                    JOptionPane.showMessageDialog(Embed.this.getParent(), "请输入密钥");
                    return;
                }

                String wm = watermarkArea.getText();
                if (wm.isEmpty() || wm == "") {
                    JOptionPane.showMessageDialog(Embed.this.getParent(), "请输入水印信息");
                }

                Embed.this.outputFilePath = outputFileArea.getText();
                Embed.this.inputFilePath = inputFileArea.getText();
                if (Embed.this.inputFilePath != null && Embed.this.inputFilePath != "" && Embed.this.outputFilePath != null && Embed.this.outputFilePath != "") {
                    if (alg.embed(Embed.this.inputFilePath, Embed.this.outputFilePath, wm, key)) {
                        inforArea.setText("嵌入成功!");
                    } else {
                        inforArea.setText("嵌入失败!" + alg.embedError);
                    }

                } else {
                    JOptionPane.showMessageDialog(Embed.this.getParent(), "请选择文件路径");
                }
            }
        });
    }

    public static void main(String[] args) {
        JFrame f = new JFrame("");
        Container contentPane = f.getContentPane();
        f.setSize(500, 400);
        f.add(new Embed());
        f.setLocation(new Point(300, 400));
        f.show();
        f.addWindowListener(new WindowListener() {
            public void windowActivated(WindowEvent arg0) {
            }

            public void windowClosed(WindowEvent arg0) {
            }

            public void windowClosing(WindowEvent arg0) {
                System.exit(0);
            }

            public void windowDeactivated(WindowEvent arg0) {
            }

            public void windowDeiconified(WindowEvent arg0) {
            }

            public void windowIconified(WindowEvent arg0) {
            }

            public void windowOpened(WindowEvent arg0) {
            }
        });
    }
}
